package com.sskj.mine.ui.activity;

import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.lzy.okgo.OkGo;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.SPConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;
import com.sskj.lib.util.TipUtil;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.component.DaggerUserDataComponent;
import com.sskj.mine.presenter.MineShopSuccessPresenter;
import com.sskj.mine.util.TipMineUtil;

import javax.inject.Inject;

import butterknife.BindInt;
import butterknife.BindView;
import butterknife.ButterKnife;

@Route(path = RConfig.MINE_SHOP_SUCCESS)//商家界面
public class MineShopSuccessActivity extends BaseActivity<MineShopSuccessPresenter> {

    @BindView(R2.id.rl_set_name)
    RelativeLayout rlSetName;
    @BindView(R2.id.rl_jc)
    RelativeLayout rlJC;
    @BindView(R2.id.nickName)
    TextView nickName;
    @Inject
    UserViewModel userViewModel;
    private UserData userData;

    @Override
    protected int getLayoutResId() {
        return R.layout.mine_activity_shop_success;
    }

    @Override
    public MineShopSuccessPresenter getPresenter() {
        return new MineShopSuccessPresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("商家认证");
        DaggerUserDataComponent.create().inject(this);
        userViewModel.getUsers().observe(this, users -> {
            if (users != null && users.size() > 0) {
                userData = users.get(0);
                nickName.setText(userData.getNickname());
            } else {
                userData = null;
            }
        });
        ClickUtil.click(rlSetName, () -> {
            TipMineUtil.setShopName(this, new TipMineUtil.OnTipPwdSure() {
                @Override
                public void onSure(String pwd) {
                    mPresenter.setShopName(SPUtil.get(SPConfig.ID, ""), pwd);
                }
            });
        });
        ClickUtil.click(rlJC, () -> {
            unBindShop();
        });
    }

    /**
     * 解除商家
     */
    private void unBindShop() {
        TipMineUtil.getShowAboutUS(this, getString(R.string.mine_sucurity_center_100),
                getString(R.string.mine_security_center_101)
                , getString(R.string.mine_security_center_102), () -> {
                    mPresenter.toggleShop();
                });
    }

    // 商家取消
    public void togglePayTypeSuccess() {
        userViewModel.update();
    }
}
